package net.oschina.dajiangnan.wx.process.msg;

import net.oschina.dajiangnan.util.XStreamHelper;
import org.apache.log4j.Logger;

import net.oschina.dajiangnan.wx.process.msg.xmlbean.ReceiveEvent;
import net.oschina.dajiangnan.wx.process.msg.xmlbean.XmlBean;


public class EventDisPatcher {

    private static Logger logger = Logger.getLogger(EventDisPatcher.class);
    
    public XmlBean process(String xmlString){
        
        ReceiveEvent receiveEvent = XStreamHelper.toBean(xmlString, ReceiveEvent.class);
        
        logger.debug("接收消息内容如下 : \r\n" + receiveEvent);
        
        XmlBean respXmlBean = null;
        
        if(receiveEvent.getEvent().equals("subscribe")){
            respXmlBean = new EventSubscribe().process(receiveEvent);
        }
        if(receiveEvent.getEvent().equals("unsubscribe")){
            new EventUnSubscribe().process(receiveEvent);
        }
        if(receiveEvent.getEvent().equals("CLICK")){
            respXmlBean = new EventClick().process(receiveEvent);
        }
        if(receiveEvent.getEvent().equals("VIEW")){
            new EventView().process(receiveEvent);
        }
        logger.debug("接收消息应答内容如下\r\n" + respXmlBean);
        
        return respXmlBean;
    }
}
